<html>
<head><meta charset="utf-8"><title>Getting mir for all (local to crate) functions in program · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Getting.20mir.20for.20all.20(local.20to.20crate).20functions.20in.20program.html">Getting mir for all (local to crate) functions in program</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236657729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Getting%20mir%20for%20all%20%28local%20to%20crate%29%20functions%20in%20program/near/236657729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hilmar Gústafsson <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Getting.20mir.20for.20all.20(local.20to.20crate).20functions.20in.20program.html#236657729">(Apr 29 2021 at 11:33)</a>:</h4>
<p>Hey, I'm struggling to find any references on how to traverse the MIR for an entire Rust program, all I could find was <code>tcx.optimized_mir(def_id)</code>, which seems to only generate mir for the given function.</p>



<a name="236658968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Getting%20mir%20for%20all%20%28local%20to%20crate%29%20functions%20in%20program/near/236658968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Getting.20mir.20for.20all.20(local.20to.20crate).20functions.20in.20program.html#236658968">(Apr 29 2021 at 11:44)</a>:</h4>
<p>Unlike HIR, MIR is not something that exists for everything. MIR only covers a single function at a time. You can use <code>tcx.mir_keys(LOCAL_CRATE)</code> to get all def ids which have MIR associated with them.</p>



<a name="236662153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Getting%20mir%20for%20all%20%28local%20to%20crate%29%20functions%20in%20program/near/236662153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hilmar Gústafsson <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Getting.20mir.20for.20all.20(local.20to.20crate).20functions.20in.20program.html#236662153">(Apr 29 2021 at 12:10)</a>:</h4>
<p>Alright, thanks! <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>